﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entities;
using DataAccess;
using MySql.Data.MySqlClient;
using System.Data;
namespace BusinessFacade
{
    public class Busi_nm_notemessage
    {
        public Busi_nm_notemessage()
        {
        }

        /// <summary>
        ///  增加一条数据
        /// </summary>
        public bool Add(nm_notemessage_Model model)
        {
            int rowsAffected;
            MySqlParameter[] parameters = {
                                               
                    new MySqlParameter("pID", MySqlDbType.Int32,11),

					new MySqlParameter("pMoubleName", MySqlDbType.VarChar,200),

					new MySqlParameter("pMoubleArea", MySqlDbType.VarChar,200),

					new MySqlParameter("pMoubleExplain", MySqlDbType.Text),

					new MySqlParameter("pMoubleContent", MySqlDbType.Text),

                    new MySqlParameter("pAuditingPerson", MySqlDbType.VarChar,200),
                                          
                    new MySqlParameter("pAuditingState",MySqlDbType.Int32),

                    new MySqlParameter("pAuditingSuggestion",MySqlDbType.Text),

                     new MySqlParameter("pCreatePersonID",MySqlDbType.Int32),

                        new MySqlParameter("pCreateTime",MySqlDbType.Date),
                                          };
            parameters[0].Direction = ParameterDirection.Output;
            parameters[1].Value = model.MoubleName;
            parameters[2].Value = model.MoubleArea;
            parameters[3].Value = model.MoubleExplain;
            parameters[4].Value = model.MoubleContent;
            parameters[5].Value = model.AuditingPerson;
            parameters[6].Value = model.AuditingState;
            parameters[7].Value = model.AuditingSuggestion;
            parameters[8].Value = model.CreatePersonID;
            parameters[9].Value = model.CreateTime;
            DbHelperMySql.RunProcedure("nm_notemessage_ADD", parameters);
            rowsAffected = int.Parse(parameters[0].Value.ToString());
            if (rowsAffected > 0)
            {
                return true;
            }
            return false;
        }



        public void Update(nm_notemessage_Model model)
        {
            MySqlParameter[] parameters = {
                   
                    new MySqlParameter("pID", MySqlDbType.Int32,11),     
                         
                    new MySqlParameter("pMoubleName", MySqlDbType.VarChar,100),

					new MySqlParameter("pMoubleArea", MySqlDbType.VarChar,100),

					new MySqlParameter("pMoubleExplain", MySqlDbType.VarChar,500),

					new MySqlParameter("pMoubleContent", MySqlDbType.VarChar,1000),

                    new MySqlParameter("pUpdatePersonID",MySqlDbType.Int32),

                    new MySqlParameter("pUpdateTime",MySqlDbType.Date)
                                          };
            parameters[0].Value = model.ID;
            parameters[1].Value = model.MoubleName;
            parameters[2].Value = model.MoubleArea;
            parameters[3].Value = model.MoubleExplain;
            parameters[4].Value = model.MoubleContent;
            parameters[5].Value = model.UpdatePersonID;
            parameters[6].Value = model.UpdateTime;

            DbHelperMySql.RunProcedure("nm_notemessage_Update", parameters);
        }
        public DataTable GetList(string UserName, int AreaID)
        {
            DataSet ds = new DataSet();
            MySqlParameter[] parameters = {
                    new MySqlParameter("MoubleName", MySqlDbType.VarChar,50),
					new MySqlParameter("MoubleArea", MySqlDbType.Int32,5)};
            parameters[0].Value = UserName;
            parameters[1].Value = AreaID;
            ds = DbHelperMySql.RunProcedure("nm_notemessage_Select", parameters);
            return ds.Tables[0];
        }
        public nm_notemessage_Model GetListModel(int id)
        {
            nm_notemessage_Model model = new nm_notemessage_Model();
            string sql = "select * from nm_notemouble where ID=" + id;
            DataSet ds = DbHelperMySql.Query(sql);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"] != null && ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    model.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["MoubleName"] != null && ds.Tables[0].Rows[0]["MoubleName"].ToString() != "")
                {
                    model.MoubleName = ds.Tables[0].Rows[0]["MoubleName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["MoubleArea"] != null && ds.Tables[0].Rows[0]["MoubleArea"].ToString() != "")
                {
                    model.MoubleArea = ds.Tables[0].Rows[0]["MoubleArea"].ToString();
                }

                if (ds.Tables[0].Rows[0]["MoubleExplain"] != null && ds.Tables[0].Rows[0]["MoubleExplain"].ToString() != "")
                {
                    model.MoubleExplain = ds.Tables[0].Rows[0]["MoubleExplain"].ToString();
                }


                if (ds.Tables[0].Rows[0]["MoubleContent"] != null && ds.Tables[0].Rows[0]["MoubleContent"].ToString() != "")
                {
                    model.MoubleContent = ds.Tables[0].Rows[0]["MoubleContent"].ToString();
                }

                return model;
            }
            model = null;
            return model;
        }
        public static void Delete(int id)
        {
            MySqlParameter[] parameters = { 
                             new MySqlParameter("pID",MySqlDbType.Int32)
                                         };
            parameters[0].Value = id;
            DbHelperMySql.RunProcedure("nm_notemessage_Delete", parameters);
        }
    }
}
